Skip to content

Conversation

@vidarl
Copy link
Contributor

@vidarl vidarl commented Nov 3, 2025

🎫 Issue IBX-3035

Description:

When using render(controller('ibexa_content::viewAction')), you can send parameters to the controller which will be available in the template.

Example:

    <h2>render controller</h2>
    {{ render(controller('ibexa_content::viewAction', {
        'contentId': content.id,
        'viewType': 'line',
        'params':
            { 'my_param': 'custom_data', }
    })) }}

    <h2>render_esi controller</h2>
    {{ render_esi(controller('ibexa_content::viewAction', {
        'contentId': content.id,
        'viewType': 'line',
        'params':
            { 'my_param': 'custom_data', }
    })) }}

This PR adds the same possibility when using ibexa_render() :

    <h2>direct</h2>
    {{ ibexa_render(content,
        {
            'viewType': 'line',
            'method': 'direct',
            'params': {
                'my_param': 'custom_data'
            }
        })
    }} <br/>

    {{ ibexa_render(location,
        {
            'viewType': 'line',
            'method': 'direct',
            'params': {
            'my_param': 'custom_data'
        }
        })
    }} <br/>

    <h2>inline</h2>
    {{ ibexa_render(content,
        {
            'viewType': 'line',
            'method': 'inline',
            'params': {
                'my_param': 'custom_data'
            }
        })
    }} <br/>

    {{ ibexa_render(location,
        {
            'viewType': 'line',
            'method': 'inline',
            'params': {
                'my_param': 'custom_data'
            }
        })
    }} <br/>


    <h2>esi</h2>
    {{ ibexa_render(content,
        {
            'viewType': 'line',
            'method': 'esi',
            'params': {
                'my_param': 'custom_data'
            }
        })
    }} <br/>

    {{ ibexa_render(location,
        {
            'viewType': 'line',
            'method': 'esi',
            'params': {
                'my_param': 'custom_data'
            }
        })
    }} <br/>

For QA:

Documentation:

@mnocon mnocon added the Doc needed The changes require some documentation label Nov 4, 2025
@vidarl vidarl force-pushed the IBX-3035_As_a_developer_I_want_to_pass_extra_atrributes_when_using_ibexa_render_Twig_function branch 2 times, most recently from 2e09071 to 1bb7be8 Compare November 4, 2025 14:09
@vidarl vidarl force-pushed the IBX-3035_As_a_developer_I_want_to_pass_extra_atrributes_when_using_ibexa_render_Twig_function branch from 1bb7be8 to 2a1ab1c Compare November 4, 2025 15:06
@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 4, 2025

);
}

public static function forwardOptionsToFragmentRenderer(MockObject $fragmentRendererMock, MockObject $valueObjectMock, string $renderStrategyClass): void
Copy link
Contributor Author

@vidarl vidarl Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This abstractions is made to avoid cut&paste of code for similar test in RenderLocationStrategyTest

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This abstractions is made to avoid cut&paste of code for similar test in RenderLocationStrategyTest

But does it have to be static?

if ($request->attributes->has('viewParametersString')) {
$uri->attributes['viewParametersString'] = $request->attributes->get('viewParametersString');
}
if ($options['params'] ?? false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refactor this so you don't rely on true-ish expression inside of the if statement. This works because of implicit cast which can lead to some bugs under some circumstances. What is the real condition making this usable? !is_empty && is_array?

}
if ($options['params'] ?? false) {
$uri->attributes['params'] = $options['params'];
unset($options['params']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This effectively changes the behavior which we can do in 6.0 ATM.

$renderer = $this->getFragmentRenderer($options->get('method', $this->defaultRenderer));

return $renderer->render($controllerReference, $currentRequest)->getContent();
return $renderer->render($controllerReference, $currentRequest, $options->has('params') ? ['params' => $options->get('params')] : [])->getContent();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Readability: please split this into multiple lines.

Personally I'd just go with:

Suggested change
return $renderer->render($controllerReference, $currentRequest, $options->has('params') ? ['params' => $options->get('params')] : [])->getContent();
return $renderer->render($controllerReference, $currentRequest, ['params' => $options->get('params', [])])->getContent();

and would've taken this into the account when processing further, effectively making params always present, reducing cognitive complexity.
But no strong feelings here.

);
}

public static function forwardOptionsToFragmentRenderer(MockObject $fragmentRendererMock, MockObject $valueObjectMock, string $renderStrategyClass): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This abstractions is made to avoid cut&paste of code for similar test in RenderLocationStrategyTest

But does it have to be static?

);
}

public static function forwardOptionsToFragmentRenderer(MockObject $fragmentRendererMock, MockObject $valueObjectMock, string $renderStrategyClass): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing PHPDoc defining type intersection for MockObject arguments.

@alongosz alongosz changed the title IBX-3035 as a developer i want to pass extra atrributes when using ibexa render_twig() function IBX-3035: [Twig] Allowed passing parameters to ibexa render function Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Doc needed The changes require some documentation Ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants